<template>
	<view :class="currentTheme">
		<a-nabbar name="提交意向" />
		<view class="u-padding-32">
			<item-box>
				<view class="want-box u-flex u-row-center">
					<view class="u-flex u-flex-col">
						<item-image :img="`${aliosCdn}/larp/common-${currentTheme}/larpData.png`" width="79" height="84"></item-image>
						<view class="u-font-30 u-text-center box-title u-margin-top-28">参展信息{{isSuccess?'已':'待'}}完善</view>
					</view>
				</view>
			</item-box>
			<view class="u-text-center u-font-32" v-if="isCity">
				<view class="txt u-font-28 content-desc-item">
					是否接受一城多限及以上？
				</view>
				<view class="u-flex u-row-center u-margin-top-62">
					<view v-for="(item, index) in list" :key="index" :class="{'u-margin-left-60':index>0}">
						<v-radio :name="item.value"   v-model="oneCityMultilimit">
							<view class=" u-font-26 text-order-time" >{{item.label}}</view>
						</v-radio>
					</view>
				</view>
			</view>
			<view class="u-margin-top-80 btns">
				<item-btn width="100%" height="88"  @click="editStoreMsg">修改参展信息</item-btn>
				<view class="u-margin-top-20">
					<item-btn width="100%" height="88" type="plain" :loading="loading" @click="confirmWant">提交意向</item-btn>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {mapGetters} from 'vuex'
	import {add,update,getDetail} from '@/api/crud.js'
	import vRadio from '@/components/itemRadio/itemRadio.vue'
	export default {
		components: {
			vRadio
		},
		data() {
			return {
				oneCityMultilimit:1,
				apiType:'userIntention',
				apiModule:"shopApi",
				option:{},
				loading:false,
				list:[{label:'接受',value:1},{label:'不接受',value:0}],
				isCity:false //一城多限
			};
		},
		computed: {
			...mapGetters(["loginForm",'token']),
			isSuccess(){ //已完善
				return this.loginForm.exhibitOperationStep==2
			},
		},
		onLoad(option) {
			this.option = option ;
			this.oneCityMultilimit = !option.oneCityMultilimit ?  1 : Number(option.oneCityMultilimit);
			getDetail(this.option,'product','shopApi','findIssueModeDtoByProductId').then(res=>{
				this.isCity = res.name==='城限'
			})
			uni.$on('setStoreIds',res=>{
				this.storeIds = res;
				this.submit()
			})
		},
		onUnload() {
			uni.$off('setStoreIds')
		},
		onShow() {
			if(this.token) this.$store.dispatch("getInfo"); //更新用户信息
		},
		methods: {
			editStoreMsg() {
				this.$u.route({
					url:'/pagesA/larpSetting/larpSetting',
					params:{
						type:"want"
					}
				})
			},
			confirmWant(){
				if(!this.isSuccess){
					this.$u.toast('请完善参展信息');
					return false;
				}
				if(this.loginForm.storeIds){
					this.$u.route({
						url:"/pagesA/selectStoreIds/selectStoreIds",
						params:{
							type:"findByExhibitUser",
							storeIds:this.loginForm.storeIds
						}
					})
					return false;
				}
				this.submit()
			},
			submit(){
				const fn = this.option.id ? update : add;
				this.loading = true;
				fn({
					...this.option,
					"oneCityMultilimit": this.oneCityMultilimit,
					"uid": this.loginForm.uid,
					showLoading:true,
					storeIds:this.storeIds,
					type:this.option.type || 'drive_car' // ob意向或者公车意向
					
				},this.apiType,this.apiModule).then(res=>{
					this.$u.toast('提交成功');
					this.loading = false;
					setTimeout(()=>{
						this.$u.route({
							type:"back"
						})
					},500)
				}).catch(()=>{
					this.loading = false;
				})
			}
		},
	}
</script>

<style lang="scss" scoped>
.txt{
	padding-top: 120rpx;
}
.txt-right{
	top: 0;
	right: 0;
}
.want-box{
	height: 300rpx;
}
.btns{
	position: absolute;
	bottom: 68rpx;
	left: 91rpx;
	right: 91rpx;
}
</style>
